package com.gxa.controller.investment;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.Result;
import com.gxa.entity.investment.Project;
import com.gxa.entity.investment.ProjectCenter;
import com.gxa.service.investment.*;
import com.gxa.vo.ProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "项目管理/历史项目")
@RestController
@RequestMapping("/intention/agreement")
public class HistoryProjectController {

    @Autowired
    private ProjectCenterService projectCenterService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private ProjectDetailsService projectDetailsService;
    @Autowired
    private RiskTraceService riskTraceService;
    @Autowired
    private CompanyService companyService;

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("列表接口")
    @PostMapping("/list/{pageNum}/{pageSize}")
    public Result<PageInfo> seletAll(@PathVariable("pageNum") Integer pageNum,
                                     @PathVariable("pageSize") Integer pageSize){
        PageInfo<ProjectCenter> pageInfo = this.projectCenterService.queryAll(pageNum, pageSize);
        return Result.success(pageInfo);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("条件查询列表接口")
    @PostMapping("/listVo")
    public Result<PageInfo> seletAll(@RequestBody ProjectVo projectVo){
        PageInfo<ProjectCenter> pageInfo = this.projectCenterService.queryByVo(projectVo);
        return Result.success(pageInfo);
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("根据id查询列表接口")
    @PostMapping("/list")
    public Result<Map> queryById(Integer id, Integer status){
        Map map = new HashMap();
        Project project = this.projectService.queryById(id);
        List list = this.projectDetailsService.queryTime(id, status);
        System.out.println(list.get(0));
        if (list!=null){
            map.put("project",project);
            map.put("list",list);
            return Result.success(map);
        }else{
            map.put("project",project);
        }
        map.put("project",project);
        return Result.success(map);
    }
}
